package cn.xttc.edu.config;

import cn.xttc.edu.util.DESUtil;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

/**
 * 加密处理工具配置类
 * @author yl
 */
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
    private final String[] encryptPropNames = {"jdbc.username","jdbc.password", "jdbc.url"};

    /**
     * 对关键的属性进行转换
     */
    @Override
    protected String convertProperty(String propertyName, String propertyValue) {
        if( isEncryptProp(propertyName) ){
            //解密
            return DESUtil.getDecryptString(propertyValue);
        }else{
            return propertyValue;
        }
    }

    private boolean isEncryptProp(String propertyName){
        for( String encryptPropertyName : encryptPropNames ){
            if( encryptPropertyName.equalsIgnoreCase(propertyName) ){
                return true;
            }
        }
        return false;
    }
}
